package com.twu.biblioteca;

/**
 * Created by fish on 14-7-25.
 */
public class Movie {
    private final String name;
    private final int year;
    private final String director;
    private final Enum<Rate> rate;

    public Movie(String name, int year, String director, Rate rate) {
        this.name = name;
        this.year = year;
        this.director = director;
        this.rate = rate;
    }

    public String getName() {
        return name;
    }

    public int getYear() {
        return year;
    }

    public String getDirector() {
        return director;
    }

    public Enum<Rate> getRate() {
        return rate;
    }

    public String displayString() {
        return String.format("%-30s\t%4d\t%-20s\t%4s", name,year,director,rate);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Movie)) return false;

        Movie movie = (Movie) o;

        if (year != movie.year) return false;
        if (!director.equals(movie.director)) return false;
        if (!name.equals(movie.name)) return false;
        if (!rate.equals(movie.rate)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + year;
        result = 31 * result + director.hashCode();
        result = 31 * result + rate.hashCode();
        return result;
    }

    enum Rate {
        UNRATED(0),ONE(1),TWO(2),THREE(3),FOUR(4),FIVE(5),SIX(6),SEVEN(7),EIGHT(8),NINE(9),TEN(10);
        private final int rate;

        Rate(int rate) {
            this.rate = rate;
        }

        public int getRate() {
            return rate;
        }

        public String toString() {
            return this.getRate()+"/10";
        }
    }
}
